package com.hosp.controller.v1;

import com.github.pagehelper.PageInfo;
import com.hosp.bean.Drugpeople;
import com.hosp.service.DrugPeopleService;
import com.hosp.vo.DrugpeopleVO;
import com.hosp.vo.PageRequestVO;
import com.hosp.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 药品-病人 API
 *
 * @author bing.zhang06@hand-china.com 2021/10/23 12:23
 **/
@Slf4j
@RestController
@RequestMapping("/drug-people")
public class DrugPeopleController {
    @Autowired
    private DrugPeopleService drugPeopleService;

    /**
     * 查询列表
     *
     * @param pageRequest 分页条件
     * @return 响应
     */
    @GetMapping("/list")
    public ResultVO<DrugpeopleVO> list(Drugpeople drugpeople, PageRequestVO pageRequest) {
        PageInfo<DrugpeopleVO> pageInfo = drugPeopleService.list(drugpeople, pageRequest);
        return new ResultVO<>(pageInfo);
    }

    /**
     * 保存
     *
     * @return 响应
     */
    @PostMapping("/save")
    public ResultVO<String> save(Drugpeople drugpeople) {
        log.debug("Drugpeople is {}.", drugpeople);

        boolean flag = drugPeopleService.save(drugpeople);

        if (flag) {
            return new ResultVO<>(200, "保存成功");
        } else {
            return new ResultVO<>(500, "保存失败");
        }
    }
}
